<template>
  <div class="city-list">
    <div class="ch-city">
      <div class="city-hander">当前城市</div>
      <div class="ch-city-list">
        <div class="button-wrapepr"><div class="button">{{this.currentCity}}</div></div>
      </div>
    </div>
    <div class="ch-city">
      <div class="city-hander">热门城市</div>
      <div class="ch-city-list button" v-for="item of hotCities" :key="item.id" @click="handleCityCick(item.name)">{{ item.name }}</div>
    </div>
    <div class="citys" v-for="(value, index) of cities" :key="index">
      <div class="citys-hander">{{ index }}</div>
      <div class="citys-list button" v-for="item of value" :key="item.id" @click="handleCityCick(item.name)">{{ item.name }}</div>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'CityList',
  props: {
    hotCities: Array,
    cities: Object
  },
  computed: {
    ...mapState({
      currentCity: 'city'
    })
  },
  methods: {
    handleCityCick (city) {
      this.changeCity(city)
      this.$router.push('/')
    },
    ...mapMutations(['changeCity'])
  }
}
</script>

<style lang="stylus" scoped>
.city-hander
  text-align center
  line-height 0.46rem
  background-color #EAEAEA
  margin-bottom 0.2rem
.ch-city
  clear both
  .ch-city-list
    width 28%
    float left
    margin 0 0.15rem 0.15rem 0.15rem
    border #CCCCCC solid 0.005rem
    line-height 0.4rem
    border-radius 10%
.citys
  clear both
  .citys-hander
    text-align center
    line-height 0.46rem
    background-color #EAEAEA
  .citys-list
    border-bottom #CCCCCC solid 0.005rem
    line-height 0.56rem
</style>
